package cn.icare.cms.controller.restful;


import cn.icare.cms.MoneyConfigService;
import cn.icare.cms.model.ro.AddItemCatRO;
import cn.icare.cms.model.ro.AddMoneyConfigRO;
import cn.icare.cms.model.vo.rest.RespMsgVO;
import cn.icare.cms.model.vo.rest.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.*;

@CrossOrigin
@RestController
@RequestMapping(value = "/rest/moneyconfig")
@Api(tags = "REST帐户配置")
public class MoneyConfigController extends BaseController {

    @Resource
    private MoneyConfigService moneyConfigService;

    @PostMapping("/save")
    @ApiOperation(value = "保存配置信息", notes = "保存配置信息")
    public ResponseEntity<RespMsgVO> saveConfig(@RequestBody AddMoneyConfigRO ro, HttpServletRequest request) {
        UserVO systemUser = getCurrentUser(request);
        String systemUserName = "";
        if (systemUser != null) {
            systemUserName = systemUser.getUsername();
        }
        boolean result = this.moneyConfigService.saveOne(ro, systemUserName);
        if (result) {
            return super.getRespOk(result);
        } else {
            return super.getRespFail("保存失败");
        }
    }

    @GetMapping("/getinfo")
    @ApiOperation(value = "查询配置信息", notes = "查询配置信息")
    public ResponseEntity<RespMsgVO> getOne() {
        return super.getRespOk(this.moneyConfigService.getOne());
    }
}
